home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / make-367.lha / make-3.67 / make.info-1 (.txt) < prev    next >
GNU Info File  |  1993-05-16  |  50KB  |  869 lines

  1. This is Info file make.info, produced by Makeinfo-1.54 from the input
  2. file make.texinfo.
  3.    This file documents the GNU Make utility, which determines
  4. automatically which pieces of a large program need to be recompiled,
  5. and issues the commands to recompile them.
  6.    This is Edition 0.42, last updated 14 May 1993, of `The GNU Make
  7. Manual', for `make', Version 3.66 Beta.
  8.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  9. Foundation, Inc.
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided also
  15. that the section entitled "GNU General Public License" is included
  16. exactly as in the original, and provided that the entire resulting
  17. derived work is distributed under the terms of a permission notice
  18. identical to this one.
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that the text of the translations of the section
  22. entitled "GNU General Public License" must be approved for accuracy by
  23. the Foundation.
  24. File: make.info,  Node: Top,  Next: Copying,  Prev: (dir),  Up: (dir)
  25.    The GNU `make' utility automatically determines which pieces of a
  26. large program need to be recompiled, and issues the commands to
  27. recompile them.
  28.    This is Edition 0.42 of the `GNU Make Manual', last updated 14 May
  29. 1993 for `make' Version 3.66 Beta.
  30.    This manual describes `make' and contains the following chapters:
  31. * Menu:
  32. * Copying::
  33. * Overview::                    Overview of `make'.
  34. * Introduction::                An introduction to `make'.
  35. * Makefiles::                   Makefiles tell `make' what to do.
  36. * Rules::                       Rules describe when a file must be remade.
  37. * Commands::                    Commands say how to remake a file.
  38. * Using Variables::             You can use variables to avoid repetition.
  39. * Conditionals::                Use or ignore parts of the makefile based
  40.                                  on the values of variables.
  41. * Functions::                   Many powerful ways to manipulate text.
  42. * make Invocation: Running.     How to invoke `make' on the command line.
  43. * Implicit Rules::              Use implicit rules to treat many files alike,
  44.                                  based on their file names.
  45. * Archives::                    How `make' can update library archives.
  46. * Features::                    Features GNU `make' has over other `make's.
  47. * Missing::                     What GNU `make' lacks from other `make's.
  48. * Makefile Conventions::        Conventions for makefiles in GNU programs.
  49. * Quick Reference::             A quick reference for experienced users.
  50. * Complex Makefile::            A real example of a straightforward,
  51.                                  but nontrivial, makefile.
  52. * Concept Index::               Index of Concepts
  53. * Name Index::                  Index of Functions, Variables, & Directives
  54.  -- The Detailed Node Listing --
  55. Overview of `make'
  56. * Preparing::                   Preparing and Running Make
  57. * Reading::                     On Reading this Text
  58. * Bugs::                        Problems and Bugs
  59. An Introduction to Makefiles
  60. * Rule Introduction::           What a rule looks like.
  61. * Simple Makefile::             A Simple Makefile
  62. * How Make Works::              How `make' Processes This Makefile
  63. * Variables Simplify::          Variables Make Makefiles Simpler
  64. * make Deduces::                Letting `make' Deduce the Commands
  65. * Combine By Dependency::       Another Style of Makefile
  66. * Cleanup::                     Rules for Cleaning the Directory
  67. Writing Makefiles
  68. * Makefile Contents::           What makefiles contain.
  69. * Makefile Names::              How to name your makefile.
  70. * Include::                     How one makefile can use another makefile.
  71. * MAKEFILES Variable::          The environment can specify extra makefiles.
  72. * Remaking Makefiles::          How makefiles get remade.
  73. * Overriding Makefiles::        How to override part of one makefile
  74.                                  with another makefile.
  75. Writing Rules
  76. * Rule Example::                An example explained.
  77. * Rule Syntax::                 General syntax explained.
  78. * Wildcards::                   Using wildcard characters such as `*'.
  79. * Directory Search::            Searching other directories for source files.
  80. * Phony Targets::               Using a target that is not a real file's name.
  81. * Force Targets::               You can use a target without commands
  82.                                   or dependencies to mark other
  83.                                   targets as phony.
  84. * Empty Targets::               When only the date matters and the
  85.                                   files are empty.
  86. * Special Targets::             Targets with special built-in meanings.
  87. * Multiple Targets::            When to make use of several targets in a rule.
  88. * Multiple Rules::              How to use several rules with the same target.
  89. * Static Pattern::              Static pattern rules apply to multiple targets
  90.                                   and can vary the dependencies according to
  91.                                   the target name.
  92. * Double-Colon::                How to use a special kind of rule to allow
  93.                                   several independent rules for one target.
  94. * Automatic Dependencies::      How to automatically generate rules giving
  95.                                  dependencies from the source files themselves.
  96. Using Wildcard Characters in File Names
  97. * Wildcard Examples::           Several examples
  98. * Wildcard Pitfall::            Problems to avoid.
  99. * Wildcard Function::           How to cause wildcard expansion where
  100.                                   it does not normally take place.
  101. Searching Directories for Dependencies
  102. * General Search::              Specifying a search path that applies
  103.                                   to every dependency.
  104. * Selective Search::            Specifying a search path
  105.                                   for a specified class of names.
  106. * Commands/Search::             How to write shell commands that work together
  107.                                   with search paths.
  108. * Implicit/Search::             How search paths affect implicit rules.
  109. * Libraries/Search::            Directory search for link libraries.
  110. Static Pattern Rules
  111. * Static Usage::                The syntax of static pattern rules.
  112. * Static versus Implicit::      When are they better than implicit rules?
  113. Writing the Commands in Rules
  114. * Echoing::                     How to control when commands are echoed.
  115. * Execution::                   How commands are executed.
  116. * Parallel::                    How commands can be executed in parallel.
  117. * Errors::                      What happens after a command execution error.
  118. * Interrupts::                  What happens when a command is interrupted.
  119. * Recursion::                   Invoking `make' from makefiles.
  120. * Sequences::                   Defining canned sequences of commands.
  121. * Empty Commands::              Defining useful, do-nothing commands.
  122. Recursive Use of `make'
  123. * MAKE Variable::               The special effects of using `$(MAKE)'.
  124. * Variables/Recursion::         How to communicate variables to a sub-`make'.
  125. * Options/Recursion::           How to communicate options to a sub-`make'.
  126. * -w Option::                   How the `-w' or `--print-directory' option
  127.                                  helps debug use of recursive `make' commands.
  128. How to Use Variables
  129. * Reference::                   How to use the value of a variable.
  130. * Flavors::                     Variables come in two flavors.
  131. * Advanced::                    Advanced features for referencing a variable.
  132. * Values::                      All the ways variables get their values.
  133. * Setting::                     How to set a variable in the makefile.
  134. * Appending::                   How to append more text to the old value
  135.                                   of a variable.
  136. * Override Directive::          How to set a variable in the makefile even if
  137.                                   the user has set it with a command argument.
  138. * Defining::                    An alternate way to set a variable
  139.                                   to a verbatim string.
  140. * Environment::                 Variable values can come from the environment.
  141. Advanced Features for Reference to Variables
  142. * Substitution Refs::           Referencing a variable with
  143.                                   substitutions on the value.
  144. * Computed Names::              Computing the name of the variable to refer to.
  145. Conditional Parts of Makefiles
  146. * Conditional Example::         Example of a conditional
  147. * Conditional Syntax::          The syntax of conditionals.
  148. * Testing Flags::               Conditionals that test flags.
  149. Functions for Transforming Text
  150. * Syntax of Functions::         How to write a function call.
  151. * Text Functions::              General-purpose text manipulation functions.
  152. * Filename Functions::          Functions for manipulating file names.
  153. * Foreach Function::            Repeat some text with controlled variation.
  154. * Origin Function::             Find where a variable got its value.
  155. * Shell Function::              Substitute the output of a shell command.
  156. How to Run `make'
  157. * Makefile Arguments::          How to specify which makefile to use.
  158. * Goals::                       How to use goal arguments to specify which
  159.                                   parts of the makefile to use.
  160. * Instead of Execution::        How to use mode flags to specify what
  161.                                   kind of thing to do with the commands
  162.                                   in the makefile other than simply
  163.                                   execute them.
  164. * Avoiding Compilation::        How to avoid recompiling certain files.
  165. * Overriding::                  How to override a variable to specify
  166.                                   an alternate compiler and other things.
  167. * Testing::                     How to proceed past some errors, to
  168.                                   test compilation.
  169. * Options Summary::             Summary of Options
  170. Using Implicit Rules
  171. * Using Implicit::              How to use an existing implicit rule
  172.                                   to get the commands for updating a file.
  173. * Catalogue of Rules::          A list of built-in implicit rules.
  174. * Implicit Variables::          How to change what predefined rules do.
  175. * Chained Rules::               How to use a chain of implicit rules.
  176. * Pattern Rules::               How to define new implicit rules.
  177. * Last Resort::                 How to defining commands for rules
  178.                                   which cannot find any.
  179. * Suffix Rules::                The old-fashioned style of implicit rule.
  180. * Search Algorithm::            The precise algorithm for applying
  181.                                   implicit rules.
  182. Defining and Redefining Pattern Rules
  183. * Pattern Intro::               An introduction to pattern rules.
  184. * Pattern Examples::            Examples of pattern rules.
  185. * Automatic::                   How to use automatic variables in the
  186.                                   commands of implicit rules.
  187. * Pattern Match::               How patterns match.
  188. * Match-Anything Rules::        Precautions you should take prior to
  189.                                   defining rules that can match any
  190.                                   target file whatever.
  191. * Canceling Rules::             How to override or cancel built-in rules.
  192. Using `make' to Update Archive Files
  193. * Archive Members::             Archive members as targets.
  194. * Archive Update::              The implicit rule for archive member targets.
  195. * Archive Suffix Rules::        You can write a special kind of suffix rule
  196.                                   for updating archives.
  197. Implicit Rule for Archive Member Targets
  198. * Archive Symbols::             How to update archive symbol directories.
  199. File: make.info,  Node: Copying,  Next: Overview,  Prev: Top,  Up: Top
  200. GNU GENERAL PUBLIC LICENSE
  201. **************************
  202.                          Version 2, June 1991
  203.      Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  204.      675 Mass Ave, Cambridge, MA 02139, USA
  205.      
  206.      Everyone is permitted to copy and distribute verbatim copies
  207.      of this license document, but changing it is not allowed.
  208. Preamble
  209. ========
  210.    The licenses for most software are designed to take away your
  211. freedom to share and change it.  By contrast, the GNU General Public
  212. License is intended to guarantee your freedom to share and change free
  213. software--to make sure the software is free for all its users.  This
  214. General Public License applies to most of the Free Software
  215. Foundation's software and to any other program whose authors commit to
  216. using it.  (Some other Free Software Foundation software is covered by
  217. the GNU Library General Public License instead.)  You can apply it to
  218. your programs, too.
  219.    When we speak of free software, we are referring to freedom, not
  220. price.  Our General Public Licenses are designed to make sure that you
  221. have the freedom to distribute copies of free software (and charge for
  222. this service if you wish), that you receive source code or can get it
  223. if you want it, that you can change the software or use pieces of it in
  224. new free programs; and that you know you can do these things.
  225.    To protect your rights, we need to make restrictions that forbid
  226. anyone to deny you these rights or to ask you to surrender the rights.
  227. These restrictions translate to certain responsibilities for you if you
  228. distribute copies of the software, or if you modify it.
  229.    For example, if you distribute copies of such a program, whether
  230. gratis or for a fee, you must give the recipients all the rights that
  231. you have.  You must make sure that they, too, receive or can get the
  232. source code.  And you must show them these terms so they know their
  233. rights.
  234.    We protect your rights with two steps: (1) copyright the software,
  235. and (2) offer you this license which gives you legal permission to copy,
  236. distribute and/or modify the software.
  237.    Also, for each author's protection and ours, we want to make certain
  238. that everyone understands that there is no warranty for this free
  239. software.  If the software is modified by someone else and passed on, we
  240. want its recipients to know that what they have is not the original, so
  241. that any problems introduced by others will not reflect on the original
  242. authors' reputations.
  243.    Finally, any free program is threatened constantly by software
  244. patents.  We wish to avoid the danger that redistributors of a free
  245. program will individually obtain patent licenses, in effect making the
  246. program proprietary.  To prevent this, we have made it clear that any
  247. patent must be licensed for everyone's free use or not licensed at all.
  248.    The precise terms and conditions for copying, distribution and
  249. modification follow.
  250.     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  251.   1. This License applies to any program or other work which contains a
  252.      notice placed by the copyright holder saying it may be distributed
  253.      under the terms of this General Public License.  The "Program",
  254.      below, refers to any such program or work, and a "work based on
  255.      the Program" means either the Program or any derivative work under
  256.      copyright law: that is to say, a work containing the Program or a
  257.      portion of it, either verbatim or with modifications and/or
  258.      translated into another language.  (Hereinafter, translation is
  259.      included without limitation in the term "modification".)  Each
  260.      licensee is addressed as "you".
  261.      Activities other than copying, distribution and modification are
  262.      not covered by this License; they are outside its scope.  The act
  263.      of running the Program is not restricted, and the output from the
  264.      Program is covered only if its contents constitute a work based on
  265.      the Program (independent of having been made by running the
  266.      Program).  Whether that is true depends on what the Program does.
  267.   2. You may copy and distribute verbatim copies of the Program's
  268.      source code as you receive it, in any medium, provided that you
  269.      conspicuously and appropriately publish on each copy an appropriate
  270.      copyright notice and disclaimer of warranty; keep intact all the
  271.      notices that refer to this License and to the absence of any
  272.      warranty; and give any other recipients of the Program a copy of
  273.      this License along with the Program.
  274.      You may charge a fee for the physical act of transferring a copy,
  275.      and you may at your option offer warranty protection in exchange
  276.      for a fee.
  277.   3. You may modify your copy or copies of the Program or any portion
  278.      of it, thus forming a work based on the Program, and copy and
  279.      distribute such modifications or work under the terms of Section 1
  280.      above, provided that you also meet all of these conditions:
  281.        a. You must cause the modified files to carry prominent notices
  282.           stating that you changed the files and the date of any change.
  283.        b. You must cause any work that you distribute or publish, that
  284.           in whole or in part contains or is derived from the Program
  285.           or any part thereof, to be licensed as a whole at no charge
  286.           to all third parties under the terms of this License.
  287.        c. If the modified program normally reads commands interactively
  288.           when run, you must cause it, when started running for such
  289.           interactive use in the most ordinary way, to print or display
  290.           an announcement including an appropriate copyright notice and
  291.           a notice that there is no warranty (or else, saying that you
  292.           provide a warranty) and that users may redistribute the
  293.           program under these conditions, and telling the user how to
  294.           view a copy of this License.  (Exception: if the Program
  295.           itself is interactive but does not normally print such an
  296.           announcement, your work based on the Program is not required
  297.           to print an announcement.)
  298.      These requirements apply to the modified work as a whole.  If
  299.      identifiable sections of that work are not derived from the
  300.      Program, and can be reasonably considered independent and separate
  301.      works in themselves, then this License, and its terms, do not
  302.      apply to those sections when you distribute them as separate
  303.      works.  But when you distribute the same sections as part of a
  304.      whole which is a work based on the Program, the distribution of
  305.      the whole must be on the terms of this License, whose permissions
  306.      for other licensees extend to the entire whole, and thus to each
  307.      and every part regardless of who wrote it.
  308.      Thus, it is not the intent of this section to claim rights or
  309.      contest your rights to work written entirely by you; rather, the
  310.      intent is to exercise the right to control the distribution of
  311.      derivative or collective works based on the Program.
  312.      In addition, mere aggregation of another work not based on the
  313.      Program with the Program (or with a work based on the Program) on
  314.      a volume of a storage or distribution medium does not bring the
  315.      other work under the scope of this License.
  316.   4. You may copy and distribute the Program (or a work based on it,
  317.      under Section 2) in object code or executable form under the terms
  318.      of Sections 1 and 2 above provided that you also do one of the
  319.      following:
  320.        a. Accompany it with the complete corresponding machine-readable
  321.           source code, which must be distributed under the terms of
  322.           Sections 1 and 2 above on a medium customarily used for
  323.           software interchange; or,
  324.        b. Accompany it with a written offer, valid for at least three
  325.           years, to give any third party, for a charge no more than your
  326.           cost of physically performing source distribution, a complete
  327.           machine-readable copy of the corresponding source code, to be
  328.           distributed under the terms of Sections 1 and 2 above on a
  329.           medium customarily used for software interchange; or,
  330.        c. Accompany it with the information you received as to the offer
  331.           to distribute corresponding source code.  (This alternative is
  332.           allowed only for noncommercial distribution and only if you
  333.           received the program in object code or executable form with
  334.           such an offer, in accord with Subsection b above.)
  335.      The source code for a work means the preferred form of the work for
  336.      making modifications to it.  For an executable work, complete
  337.      source code means all the source code for all modules it contains,
  338.      plus any associated interface definition files, plus the scripts
  339.      used to control compilation and installation of the executable.
  340.      However, as a special exception, the source code distributed need
  341.      not include anything that is normally distributed (in either
  342.      source or binary form) with the major components (compiler,
  343.      kernel, and so on) of the operating system on which the executable
  344.      runs, unless that component itself accompanies the executable.
  345.      If distribution of executable or object code is made by offering
  346.      access to copy from a designated place, then offering equivalent
  347.      access to copy the source code from the same place counts as
  348.      distribution of the source code, even though third parties are not
  349.      compelled to copy the source along with the object code.
  350.   5. You may not copy, modify, sublicense, or distribute the Program
  351.      except as expressly provided under this License.  Any attempt
  352.      otherwise to copy, modify, sublicense or distribute the Program is
  353.      void, and will automatically terminate your rights under this
  354.      License.  However, parties who have received copies, or rights,
  355.      from you under this License will not have their licenses
  356.      terminated so long as such parties remain in full compliance.
  357.   6. You are not required to accept this License, since you have not
  358.      signed it.  However, nothing else grants you permission to modify
  359.      or distribute the Program or its derivative works.  These actions
  360.      are prohibited by law if you do not accept this License.
  361.      Therefore, by modifying or distributing the Program (or any work
  362.      based on the Program), you indicate your acceptance of this
  363.      License to do so, and all its terms and conditions for copying,
  364.      distributing or modifying the Program or works based on it.
  365.   7. Each time you redistribute the Program (or any work based on the
  366.      Program), the recipient automatically receives a license from the
  367.      original licensor to copy, distribute or modify the Program
  368.      subject to these terms and conditions.  You may not impose any
  369.      further restrictions on the recipients' exercise of the rights
  370.      granted herein.  You are not responsible for enforcing compliance
  371.      by third parties to this License.
  372.   8. If, as a consequence of a court judgment or allegation of patent
  373.      infringement or for any other reason (not limited to patent
  374.      issues), conditions are imposed on you (whether by court order,
  375.      agreement or otherwise) that contradict the conditions of this
  376.      License, they do not excuse you from the conditions of this
  377.      License.  If you cannot distribute so as to satisfy simultaneously
  378.      your obligations under this License and any other pertinent
  379.      obligations, then as a consequence you may not distribute the
  380.      Program at all.  For example, if a patent license would not permit
  381.      royalty-free redistribution of the Program by all those who
  382.      receive copies directly or indirectly through you, then the only
  383.      way you could satisfy both it and this License would be to refrain
  384.      entirely from distribution of the Program.
  385.      If any portion of this section is held invalid or unenforceable
  386.      under any particular circumstance, the balance of the section is
  387.      intended to apply and the section as a whole is intended to apply
  388.      in other circumstances.
  389.      It is not the purpose of this section to induce you to infringe any
  390.      patents or other property right claims or to contest validity of
  391.      any such claims; this section has the sole purpose of protecting
  392.      the integrity of the free software distribution system, which is
  393.      implemented by public license practices.  Many people have made
  394.      generous contributions to the wide range of software distributed
  395.      through that system in reliance on consistent application of that
  396.      system; it is up to the author/donor to decide if he or she is
  397.      willing to distribute software through any other system and a
  398.      licensee cannot impose that choice.
  399.      This section is intended to make thoroughly clear what is believed
  400.      to be a consequence of the rest of this License.
  401.   9. If the distribution and/or use of the Program is restricted in
  402.      certain countries either by patents or by copyrighted interfaces,
  403.      the original copyright holder who places the Program under this
  404.      License may add an explicit geographical distribution limitation
  405.      excluding those countries, so that distribution is permitted only
  406.      in or among countries not thus excluded.  In such case, this
  407.      License incorporates the limitation as if written in the body of
  408.      this License.
  409.  10. The Free Software Foundation may publish revised and/or new
  410.      versions of the General Public License from time to time.  Such
  411.      new versions will be similar in spirit to the present version, but
  412.      may differ in detail to address new problems or concerns.
  413.      Each version is given a distinguishing version number.  If the
  414.      Program specifies a version number of this License which applies
  415.      to it and "any later version", you have the option of following
  416.      the terms and conditions either of that version or of any later
  417.      version published by the Free Software Foundation.  If the Program
  418.      does not specify a version number of this License, you may choose
  419.      any version ever published by the Free Software Foundation.
  420.  11. If you wish to incorporate parts of the Program into other free
  421.      programs whose distribution conditions are different, write to the
  422.      author to ask for permission.  For software which is copyrighted
  423.      by the Free Software Foundation, write to the Free Software
  424.      Foundation; we sometimes make exceptions for this.  Our decision
  425.      will be guided by the two goals of preserving the free status of
  426.      all derivatives of our free software and of promoting the sharing
  427.      and reuse of software generally.
  428.                                 NO WARRANTY
  429.  12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  430.      WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  431.      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  432.      HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  433.      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  434.      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  435.      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  436.      QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  437.      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  438.      SERVICING, REPAIR OR CORRECTION.
  439.  13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  440.      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  441.      MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  442.      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  443.      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  444.      INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  445.      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  446.      OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  447.      OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  448.      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  449.                       END OF TERMS AND CONDITIONS
  450. How to Apply These Terms to Your New Programs
  451. =============================================
  452.    If you develop a new program, and you want it to be of the greatest
  453. possible use to the public, the best way to achieve this is to make it
  454. free software which everyone can redistribute and change under these
  455. terms.
  456.    To do so, attach the following notices to the program.  It is safest
  457. to attach them to the start of each source file to most effectively
  458. convey the exclusion of warranty; and each file should have at least
  459. the "copyright" line and a pointer to where the full notice is found.
  460.      ONE LINE TO GIVE THE PROGRAM'S NAME AND AN IDEA OF WHAT IT DOES.
  461.      Copyright (C) 19YY  NAME OF AUTHOR
  462.      
  463.      This program is free software; you can redistribute it and/or
  464.      modify it under the terms of the GNU General Public License
  465.      as published by the Free Software Foundation; either version 2
  466.      of the License, or (at your option) any later version.
  467.      
  468.      This program is distributed in the hope that it will be useful,
  469.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  470.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  471.      GNU General Public License for more details.
  472.      
  473.      You should have received a copy of the GNU General Public License
  474.      along with this program; if not, write to the Free Software
  475.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  476.    Also add information on how to contact you by electronic and paper
  477. mail.
  478.    If the program is interactive, make it output a short notice like
  479. this when it starts in an interactive mode:
  480.      Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
  481.      Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
  482.      type `show w'.  This is free software, and you are welcome
  483.      to redistribute it under certain conditions; type `show c'
  484.      for details.
  485.    The hypothetical commands `show w' and `show c' should show the
  486. appropriate parts of the General Public License.  Of course, the
  487. commands you use may be called something other than `show w' and `show
  488. c'; they could even be mouse-clicks or menu items--whatever suits your
  489. program.
  490.    You should also get your employer (if you work as a programmer) or
  491. your school, if any, to sign a "copyright disclaimer" for the program,
  492. if necessary.  Here is a sample; alter the names:
  493.      Yoyodyne, Inc., hereby disclaims all copyright
  494.      interest in the program `Gnomovision'
  495.      (which makes passes at compilers) written
  496.      by James Hacker.
  497.      
  498.      SIGNATURE OF TY COON, 1 April 1989
  499.      Ty Coon, President of Vice
  500.    This General Public License does not permit incorporating your
  501. program into proprietary programs.  If your program is a subroutine
  502. library, you may consider it more useful to permit linking proprietary
  503. applications with the library.  If this is what you want to do, use the
  504. GNU Library General Public License instead of this License.
  505. File: make.info,  Node: Overview,  Next: Introduction,  Prev: Copying,  Up: Top
  506. Overview of `make'
  507. ******************
  508.    The `make' utility automatically determines which pieces of a large
  509. program need to be recompiled, and issues commands to recompile them.
  510. This manual describes GNU `make', which was implemented by Richard
  511. Stallman and Roland McGrath.  GNU `make' conforms to section 6.2 of
  512. `IEEE Standard 1003.2-1992' (POSIX.2).
  513.    Our examples show C programs, since they are most common, but you
  514. can use `make' with any programming language whose compiler can be run
  515. with a shell command.  Indeed, `make' is not limited to programs.  You
  516. can use it to describe any task where some files must be updated
  517. automatically from others whenever the others change.
  518. * Menu:
  519. * Preparing::                   Preparing and Running Make
  520. * Reading::                     On Reading this Text
  521. * Bugs::                        Problems and Bugs
  522. File: make.info,  Node: Preparing,  Next: Reading,  Up: Overview
  523. Preparing and Running Make
  524. ==========================
  525.    To prepare to use `make', you must write a file called the
  526. "makefile" that describes the relationships among files in your program
  527. and provides commands for updating each file.  In a program, typically,
  528. the executable file is updated from object files, which are in turn
  529. made by compiling source files.
  530.    Once a suitable makefile exists, each time you change some source
  531. files, this simple shell command:
  532.      make
  533. suffices to perform all necessary recompilations.  The `make' program
  534. uses the makefile data base and the last-modification times of the
  535. files to decide which of the files need to be updated.  For each of
  536. those files, it issues the commands recorded in the data base.
  537.    You can provide command line arguments to `make' to control which
  538. files should be recompiled, or how.  *Note How to Run `make': Running.
  539. File: make.info,  Node: Reading,  Next: Bugs,  Prev: Preparing,  Up: Overview
  540. How to Read This Manual
  541. =======================
  542.    If you are new to `make', or are looking for a general introduction,
  543. read the first few sections of each chapter, skipping the later
  544. sections.  In each chapter, the first few sections contain introductory
  545. or general information and the later sections contain specialized or
  546. technical information.  The exception is the second chapter, *Note An
  547. Introduction to Makefiles: Introduction, all of which is introductory.
  548.    If you are familiar with other `make' programs, see *Note Features
  549. of GNU `make': Features, which lists the enhancements GNU `make' has,
  550. and *Note Incompatibilities and Missing Features: Missing, which
  551. explains the few things GNU `make' lacks that others have.
  552.    For a quick summary, see *Note Options Summary::, *Note Quick
  553. Reference::, and *Note Special Targets::.
  554. File: make.info,  Node: Bugs,  Prev: Reading,  Up: Overview
  555. Problems and Bugs
  556. =================
  557.    If you have problems with GNU `make' or think you've found a bug,
  558. please report it to the developers; we cannot promise to do anything but
  559. we might well want to fix it.
  560.    Before reporting a bug, make sure you've actually found a real bug.
  561. Carefully reread the documentation and see if it really says you can do
  562. what you're trying to do.  If it's not clear whether you should be able
  563. to do something or not, report that too; it's a bug in the
  564. documentation!
  565.    Before reporting a bug or trying to fix it yourself, try to isolate
  566. it to the smallest possible makefile that reproduces the problem.  Then
  567. send us the makefile and the exact results `make' gave you.  Also say
  568. what you expected to occur; this will help us decide whether the
  569. problem was really in the documentation.
  570.    Once you've got a precise problem, please send electronic mail either
  571. through the Internet or via UUCP:
  572.      Internet address:
  573.          bug-gnu-utils@prep.ai.mit.edu
  574.      
  575.      UUCP path:
  576.          mit-eddie!prep.ai.mit.edu!bug-gnu-utils
  577. Please include the version number of `make' you are using.  You can get
  578. this information with the command `make --version'.  Be sure also to
  579. include the type of machine and operating system you are using.  If
  580. possible, include the contents of the file `config.h' that is generated
  581. by the configuration process.
  582.    Non-bug suggestions are always welcome as well.  If you have
  583. questions about things that are unclear in the documentation or are
  584. just obscure features, contact Roland McGrath; he will try to help you
  585. out, although he may not have time to fix the problem.
  586.    You can send electronic mail to Roland McGrath either through the
  587. Internet or via UUCP:
  588.      Internet address:
  589.          roland@prep.ai.mit.edu
  590.      
  591.      UUCP path:
  592.          mit-eddie!prep.ai.mit.edu!roland
  593. File: make.info,  Node: Introduction,  Next: Makefiles,  Prev: Overview,  Up: Top
  594. An Introduction to Makefiles
  595. ****************************
  596.    You need a file called a "makefile" to tell `make' what to do.  Most
  597. often, the makefile tells `make' how to compile and link a program.
  598.    In this chapter, we will discuss a simple makefile that describes
  599. how to compile and link a text editor which consists of eight C source
  600. files and three header files.  The makefile can also tell `make' how to
  601. run miscellaneous commands when explicitly asked (for example, to remove
  602. certain files as a clean-up operation).  To see a more complex example
  603. of a makefile, see *Note Complex Makefile::.
  604.    When `make' recompiles the editor, each changed C source file must
  605. be recompiled.  If a header file has changed, each C source file that
  606. includes the header file must be recompiled to be safe.  Each
  607. compilation produces an object file corresponding to the source file.
  608. Finally, if any source file has been recompiled, all the object files,
  609. whether newly made or saved from previous compilations, must be linked
  610. together to produce the new executable editor.
  611. * Menu:
  612. * Rule Introduction::           What a rule looks like.
  613. * Simple Makefile::             A Simple Makefile
  614. * How Make Works::              How `make' Processes This Makefile
  615. * Variables Simplify::          Variables Make Makefiles Simpler
  616. * make Deduces::                Letting `make' Deduce the Commands
  617. * Combine By Dependency::       Another Style of Makefile
  618. * Cleanup::                     Rules for Cleaning the Directory
  619. File: make.info,  Node: Rule Introduction,  Next: Simple Makefile,  Up: Introduction
  620. What a Rule Looks Like
  621. ======================
  622.    A simple makefile consists of "rules" with the following shape:
  623.      TARGET ... : DEPENDENCIES ...
  624.              COMMAND
  625.              ...
  626.              ...
  627.    A "target" is usually the name of a file that is generated by a
  628. program; examples of targets are executable or object files.  A target
  629. can also be the name of an action to carry out, such as `clean' (*note
  630. Phony Targets::.).
  631.    A "dependency" is a file that is used as input to create the target.
  632. A target often depends on several files.
  633.    A "command" is an action that `make' carries out.  A rule may have
  634. more than one command, each on its own line.  *Please note:* you need
  635. to put a tab character at the beginning of every command line!  This is
  636. an obscurity that catches the unwary.
  637.    Usually a command is in a rule with dependencies and serves to
  638. create a target file if any of the dependencies change.  However, the
  639. rule that specifies commands for the target need not have dependencies.
  640. For example, the rule containing the delete command associated with the
  641. target `clean' does not have dependencies.
  642.    A "rule", then, explains how and when to remake certain files which
  643. are the targets of the particular rule.  `make' carries out the
  644. commands on the dependencies to create or update the target.  A rule
  645. can also explain how and when to carry out an action.  *Note Writing
  646. Rules: Rules.
  647.    A makefile may contain other text besides rules, but a simple
  648. makefile need only contain rules.  Rules may look somewhat more
  649. complicated than shown in this template, but all fit the pattern more
  650. or less.
  651. File: make.info,  Node: Simple Makefile,  Next: How Make Works,  Prev: Rule Introduction,  Up: Introduction
  652. A Simple Makefile
  653. =================
  654.    Here is a straightforward makefile that describes the way an
  655. executable file called `edit' depends on eight object files which, in
  656. turn, depend on eight C source and three header files.
  657.    In this example, all the C files include `defs.h', but only those
  658. defining editing commands include `command.h', and only low level files
  659. that change the editor buffer include `buffer.h'.
  660.      edit : main.o kbd.o command.o display.o \
  661.             insert.o search.o files.o utils.o
  662.              cc -o edit main.o kbd.o command.o display.o \
  663.                         insert.o search.o files.o utils.o
  664.      
  665.      main.o : main.c defs.h
  666.              cc -c main.c
  667.      kbd.o : kbd.c defs.h command.h
  668.              cc -c kbd.c
  669.      command.o : command.c defs.h command.h
  670.              cc -c command.c
  671.      display.o : display.c defs.h buffer.h
  672.              cc -c display.c
  673.      insert.o : insert.c defs.h buffer.h
  674.              cc -c insert.c
  675.      search.o : search.c defs.h buffer.h
  676.              cc -c search.c
  677.      files.o : files.c defs.h buffer.h command.h
  678.              cc -c files.c
  679.      utils.o : utils.c defs.h
  680.              cc -c utils.c
  681.      clean :
  682.              rm edit main.o kbd.o command.o display.o \
  683.                 insert.o search.o files.o utils.o
  684. We split each long line into two lines using backslash-newline; this is
  685. like using one long line, but is easier to read.
  686.    To use this makefile to create the executable file called `edit',
  687. type:
  688.      make
  689.    To use this makefile to delete the executable file and all the object
  690. files from the directory, type:
  691.      make clean
  692.    In the example makefile, the targets include the executable file
  693. `edit', and the object files `main.o' and `kbd.o'.  The dependencies
  694. are files such as `main.c' and `defs.h'.  In fact, each `.o' file is
  695. both a target and a dependency.  Commands include `cc -c main.c' and
  696. `cc -c kbd.c'.
  697.    When a target is a file, it needs to be recompiled or relinked if any
  698. of its dependencies change.  In addition, any dependencies that are
  699. themselves automatically generated should be updated first.  In this
  700. example, `edit' depends on each of the eight object files; the object
  701. file `main.o' depends on the source file `main.c' and on the header
  702. file `defs.h'.
  703.    A shell command follows each line that contains a target and
  704. dependencies.  These shell commands say how to update the target file.
  705. A tab character must come at the beginning of every command line to
  706. distinguish commands lines from other lines in the makefile.  (Bear in
  707. mind that `make' does not know anything about how the commands work.
  708. It is up to you to supply commands that will update the target file
  709. properly.  All `make' does is execute the commands in the rule you have
  710. specified when the target file needs to be updated.)
  711.    The target `clean' is not a file, but merely the name of an action.
  712. Since you normally do not want to carry out the actions in this rule,
  713. `clean' is not a dependency of any other rule.  Consequently, `make'
  714. never does anything with it unless you tell it specifically.  Note that
  715. this rule not only is not a dependency, it also does not have any
  716. dependencies, so the only purpose of the rule is to run the specified
  717. commands.  Targets that do not refer to files but are just actions are
  718. called "phony targets".  *Note Phony Targets::, for information about
  719. this kind of target.  *Note Errors in Commands: Errors, to see how to
  720. cause `make' to ignore errors from `rm' or any other command.
  721. File: make.info,  Node: How Make Works,  Next: Variables Simplify,  Prev: Simple Makefile,  Up: Introduction
  722. How `make' Processes a Makefile
  723. ===============================
  724.    By default, `make' starts with the first rule (not counting rules
  725. whose target names start with `.').  This is called the "default goal".
  726. ("Goals" are the targets that `make' strives ultimately to update.
  727. *Note Arguments to Specify the Goals: Goals.)
  728.    In the simple example of the previous section, the default goal is to
  729. update the executable program `edit'; therefore, we put that rule first.
  730.    Thus, when you give the command:
  731.      make
  732. `make' reads the makefile in the current directory and begins by
  733. processing the first rule.  In the example, this rule is for relinking
  734. `edit'; but before `make' can fully process this rule, it must process
  735. the rules for the files that `edit' depends on, which in this case are
  736. the object files.  Each of these files is processed according to its
  737. own rule.  These rules say to update each `.o' file by compiling its
  738. source file.  The recompilation must be done if the source file, or any
  739. of the header files named as dependencies, is more recent than the
  740. object file, or if the object file does not exist.
  741.    The other rules are processed because their targets appear as
  742. dependencies of the goal.  If some other rule is not depended on by the
  743. goal (or anything it depends on, etc.), that rule is not processed,
  744. unless you tell `make' to do so (with a command such as `make clean').
  745.    Before recompiling an object file, `make' considers updating its
  746. dependencies, the source file and header files.  This makefile does not
  747. specify anything to be done for them--the `.c' and `.h' files are not
  748. the targets of any rules--so `make' does nothing for these files.  But
  749. `make' would update automatically generated C programs, such as those
  750. made by Bison or Yacc, by their own rules at this time.
  751.    After recompiling whichever object files need it, `make' decides
  752. whether to relink `edit'.  This must be done if the file `edit' does
  753. not exist, or if any of the object files are newer than it.  If an
  754. object file was just recompiled, it is now newer than `edit', so `edit'
  755. is relinked.
  756.    Thus, if we change the file `insert.c' and run `make', `make' will
  757. compile that file to update `insert.o', and then link `edit'.  If we
  758. change the file `command.h' and run `make', `make' will recompile the
  759. object files `kbd.o', `command.o' and `files.o' and then link the file
  760. `edit'.
  761. File: make.info,  Node: Variables Simplify,  Next: make Deduces,  Prev: How Make Works,  Up: Introduction
  762. Variables Make Makefiles Simpler
  763. ================================
  764.    In our example, we had to list all the object files twice in the
  765. rule for `edit' (repeated here):
  766.      edit : main.o kbd.o command.o display.o \
  767.                    insert.o search.o files.o utils.o
  768.              cc -o edit main.o kbd.o command.o display.o \
  769.                         insert.o search.o files.o utils.o
  770.    Such duplication is error-prone; if a new object file is added to the
  771. system, we might add it to one list and forget the other.  We can
  772. eliminate the risk and simplify the makefile by using a variable.
  773. "Variables" allow a text string to be defined once and substituted in
  774. multiple places later (*note How to Use Variables: Using Variables.).
  775.    It is standard practice for every makefile to have a variable named
  776. `objects', `OBJECTS', `objs', `OBJS', `obj', or `OBJ' which is a list
  777. of all object file names.  We would define such a variable `objects'
  778. with a line like this in the makefile:
  779.      objects = main.o kbd.o command.o display.o \
  780.                insert.o search.o files.o utils.o
  781. Then, each place we want to put a list of the object file names, we can
  782. substitute the variable's value by writing `$(objects)' (*note How to
  783. Use Variables: Using Variables.).
  784.    Here is how the complete simple makefile looks when you use a
  785. variable for the object files:
  786.      objects = main.o kbd.o command.o display.o \
  787.                insert.o search.o files.o utils.o
  788.      
  789.      edit : $(objects)
  790.              cc -o edit $(objects)
  791.      main.o : main.c defs.h
  792.              cc -c main.c
  793.      kbd.o : kbd.c defs.h command.h
  794.              cc -c kbd.c
  795.      command.o : command.c defs.h command.h
  796.              cc -c command.c
  797.      display.o : display.c defs.h buffer.h
  798.              cc -c display.c
  799.      insert.o : insert.c defs.h buffer.h
  800.              cc -c insert.c
  801.      search.o : search.c defs.h buffer.h
  802.              cc -c search.c
  803.      files.o : files.c defs.h buffer.h command.h
  804.              cc -c files.c
  805.      utils.o : utils.c defs.h
  806.              cc -c utils.c
  807.      clean :
  808.              rm edit $(objects)
  809. File: make.info,  Node: make Deduces,  Next: Combine By Dependency,  Prev: Variables Simplify,  Up: Introduction
  810. Letting `make' Deduce the Commands
  811. ==================================
  812.    It is not necessary to spell out the commands for compiling the
  813. individual C source files, because `make' can figure them out: it has an
  814. "implicit rule" for updating a `.o' file from a correspondingly named
  815. `.c' file using a `cc -c' command.  For example, it will use the
  816. command `cc -c main.c -o main.o' to compile `main.c' into `main.o'.  We
  817. can therefore omit the commands from the rules for the object files.
  818. *Note Using Implicit Rules: Implicit Rules.
  819.    When a `.c' file is used automatically in this way, it is also
  820. automatically added to the list of dependencies.  We can therefore omit
  821. the `.c' files from the dependencies, provided we omit the commands.
  822.    Here is the entire example, with both of these changes, and a
  823. variable `objects' as suggested above:
  824.      objects = main.o kbd.o command.o display.o \
  825.                insert.o search.o files.o utils.o
  826.      
  827.      edit : $(objects)
  828.              cc -o edit $(objects)
  829.      
  830.      main.o : defs.h
  831.      kbd.o : defs.h command.h
  832.      command.o : defs.h command.h
  833.      display.o : defs.h buffer.h
  834.      insert.o : defs.h buffer.h
  835.      search.o : defs.h buffer.h
  836.      files.o : defs.h buffer.h command.h
  837.      utils.o : defs.h
  838.      
  839.      .PHONY : clean
  840.      clean :
  841.              -rm edit $(objects)
  842. This is how we would write the makefile in actual practice.  (The
  843. complications associated with `clean' are described elsewhere.  See
  844. *Note Phony Targets::, and *Note Errors in Commands: Errors.)
  845.    Because implicit rules are so convenient, they are important.  You
  846. will see them used frequently.
  847. File: make.info,  Node: Combine By Dependency,  Next: Cleanup,  Prev: make Deduces,  Up: Introduction
  848. Another Style of Makefile
  849. =========================
  850.    When the objects of a makefile are created only by implicit rules, an
  851. alternative style of makefile is possible.  In this style of makefile,
  852. you group entries by their dependencies instead of by their targets.
  853. Here is what one looks like:
  854.      objects = main.o kbd.o command.o display.o \
  855.                insert.o search.o files.o utils.o
  856.      
  857.      edit : $(objects)
  858.              cc -o edit $(objects)
  859.      
  860.      $(objects) : defs.h
  861.      kbd.o command.o files.o : command.h
  862.      display.o insert.o search.o files.o : buffer.h
  863. Here `defs.h' is given as a dependency of all the object files;
  864. `command.h' and `buffer.h' are dependencies of the specific object
  865. files listed for them.
  866.    Whether this is better is a matter of taste: it is more compact, but
  867. some people dislike it because they find it clearer to put all the
  868. information about each target in one place.
  869.